<?php include("head.php");
      include_once("paging_function.php");

if(isset($_POST['Submit']) && $_POST['Submit'] == 'Edit')
{
			//==========================================value asigin==========================================================//
			 $id=$_REQUEST['id'];
			 $news=$_POST['newsTitle'];
			 $newsDetails=$_POST['newsDetails'];
	
	//--------------------------------------database update-----------------------------------------------------------//
	
			mysql_query("update ".SITENEWS." set newsTitle='".$news."',newsDetails='".$newsDetails."', newsAdDate=NOW() where latestNewsId='".$id."'");

	echo '<script>window.location="latestNewsManage.php?action=show&id='.$id.'&a=done"</script>';
//=====================================value define=======================================================//
   
 }
if(isset($_POST['Submit']) && $_POST['Submit'] == 'Insert')
{
	$news=$_POST['newsTitle'];
	$newsDetails=addslashes($_POST['newsDetails']);
	//////////////////////////insert into database/////////////////////////////////////
		mysql_query("insert into ".SITENEWS." set newsTitle='".$news."' ,newsDetails='".$newsDetails."' ,  	newsAdDate=NOW()") or die(mysql_error());
	echo '<script>window.location="latestNewsManage.php?a=insert"</script>';

}
 
 
 
 
//===========================================delete==============================================================
if(isset($_REQUEST['submit1']))
   {
$id=$_REQUEST['del'];

for($i=0;$i<count($id);$i++)
      {
       $sql="delete  from ".SITENEWS." where latestNewsId='".$id[$i]."'";
       mysql_query($sql);
        echo '<script>window.location="latestNewsManage.php?a=del"</script>';
      }

    }
?>
<?php


$db = mysql_query("SELECT * FROM ".GLOBALSETTINGS);
$fet = mysql_fetch_array($db);
$lim=$adminpagelimit;
?>
<SCRIPT LANGUAGE="JavaScript">
function popUp(URL) {

id =0;
eval("page" + id + " = window.open(URL, '" + id + "', 'status=0,toolbar=0,menubar=0,resizable=0,dependent=0,width=400,height=400,left=25,top=25');");
}
</script>

<script language="javascript">
function valid()
{
if(document.latestNews.newsTitle.value.search(/\S/)==-1)
    {
    alert("Please Enter News Title");
    document.latestNews.newsTitle.focus();
    return false;
    }
if(document.latestNews.answer.value=="")
        {
          alert("Enter Latest News...");
          document.latestNews.newsDetails.focus();
          return false;
        }
        return true;
}
</script>
<?php
if(isset($_GET['page']))
		{
		
			$page = $_GET['page'];
		}
	else
		{
			$page = 0;
		}
       $limit=$lim;
?>
<?php
$sql1="select * from ".SITENEWS." where latestNewsId='".$_REQUEST['id']."'";

 $query1=mysql_query($sql1);

 $fetch=mysql_fetch_array($query1);


?>
<fieldset>

	<legend class="LEGEND"><strong>Latest News</strong></legend>
		<table width="100%">
		<tr><td>
		<table width="100%" align="center" >
		<tr>
		<td>
		
		<form name="latestNews" action="" method="POST" onsubmit="return valid()">
		
		<table width="550" border="0" cellspacing="0" cellpadding="0" align="left">
				<tr>
				<td align="left" valign="top" class="signin_tlgap" colspan="3"><b>Write Latest News here.</b></td>
			  </tr>
		<?php $msg=$_REQUEST['a'];
			  
			  if($msg == 'insert')
			   {?>
		<tr>  
			  <td colspan="3" align="left"><font color="Red">Thank You Successfully insert</font></td>
		</tr>  
		<?php  }?>
		<?php //$msg=$_REQUEST['del'];
			  if($msg == 'del')
			   {?>
		<tr>  
			  <td colspan="3" align="left"><font color="Red">Thank You Successfully delete</font></td>
		</tr>  
		<?php  }
			  elseif($msg == 'done') {?> 
		<tr>  
			  <td colspan="3" align="left"><font color="Red">Thank You Successfully edit</font></td>
		</tr>  
		  <?php
		  	}
		  ?>
			  <tr>
				<td align="left" valign="top" class="signin_tlgap" colspan="2">&nbsp;</td>
				<td align="left" valign="top" class="refer_rgap">&nbsp;</td>
			  </tr>
		
				  <tr>
					<td align="left" valign="top" class="con_tlcon"><strong>News Title </strong></td>
					<td align="left" valign="top"><input type="text" name="newsTitle" value="<?php echo $fetch['newsTitle'];?>" size="<?php if($fetch['newsTitle'] != '') echo (int)(strlen($fetch['newsTitle']) + 2); else echo "42"; ?>"></td>
					<td align="left" valign="top" class="con_rgap">&nbsp;</td>
				  </tr>
				  <tr>
					<td align="left" valign="top" class="con_tlcon">&nbsp;</td>
					<td align="left" valign="top" class="con_box">&nbsp;</td>
					<td align="left" valign="top" class="con_rgap">&nbsp;</td>
				  </tr>
				  <tr>
					<td align="left" valign="top" class="con_tlcon"><strong>Latest News</strong></td>
					<td align="left" valign="top" class="con_box"><textarea class="submit_text_area_1" name="newsDetails"  cols="40" rows="7"><?php echo stripslashes($fetch['newsDetails']);?></textarea></td>
					<td align="left" valign="top" class="con_rgap">&nbsp;</td>
				  </tr>
				  
				  <tr>News Management
					<td align="left" valign="top" class="con_tlcon">&nbsp;</td>
					<td align="left" valign="top" class="con_box">&nbsp;</td>
					<td align="left" valign="top" class="con_rgap">&nbsp;</td>
				  </tr>
				  
					  <tr>
					<td align="left" valign="top" class="con_tlcon">&nbsp;</td>
					<td align="left" valign="top" class="con_box"><span class="con_rgap">
					  <input type="submit" name="Submit" value="<?php if($_REQUEST['action']=='show'){echo 'Edit';}else echo 'Insert';?>" />
					</span><?php if($_REQUEST['action']=='show'){?><input type="button" value="Back"  onClick="javascript:window.location='latestNewsManage.php';" name="back"><?php } ?>
							</td>
					<td align="left" valign="top" class="con_rgap">&nbsp;</td>
					  </tr>
			  </table>
		</form>
		
		
		</td></tr>
		
		<?php   //---------------------------------query to show the form----------------------------------------------//
		#echo FAQ.'<br><br>';
		$sql1="select * from ".SITENEWS." order by latestNewsId desc limit $page,$limit";
		
		#echo $sql1.'<br>';
		$show=mysql_query($sql1);
		#echo mysql_field_name($show,1);
		//print_r();
		?>
		<?php
		
		while($fetch=mysql_fetch_array($show))
			{
		 ?>
		 <tr>
		   <td>&nbsp;</td>
		 </tr>
		 <tr><td>
		<form name="show" action="" method="POST">
		   <table width="100%" border="0" cellspacing="2" cellpadding="2" align="left" >
			  <tr>
			  <td>
				 <table width="100%" border="0" cellspacing="0" cellpadding="3" align="left" bgcolor="#F5F2FF">
				   <tr bgcolor="#A2AFDF" >
					<td align="center" valign="middle" width="80" height="30"><strong>News Title : </strong></td>
					<td align="left" valign="middle"  class="con_box"><?php echo $fetch['newsTitle'];?></td>
				   </tr>
				   
				   <tr>
					<td align="center" valign="middle" width="80" height="30" ><strong>Latest News : </strong></td>
					<td><?php echo stripslashes($fetch['newsDetails']);?></td>
					</tr>
				  <tr>
					<td>&nbsp;</td>
					<td align="right"><a href="latestNewsManage.php?action=show&id=<?php echo $fetch['latestNewsId'];?>" ><img src="images/edit_icon.gif" border="0"/></a>&nbsp;&nbsp;&nbsp;<input type="checkbox" value="<?php echo  $fetch['latestNewsId'];?> "  name="del[]"/>&nbsp;&nbsp;<input type="submit" name="submit1" value="delete"></td>
				  </tr>
				  </table>  
			   </td>
			  </tr>
		   </table>
		</form></td></tr>
		<?php } ?>
		
		
		<TR>
		<TD align="center"><?php echo paging($sql1,$page,$limit,'');?></TD>
		</TR>
		</table>
		</td></tr>
		</table>
</fieldset>	  
	  
	  
<?php
include_once("foot.php");
?>